<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/23
 * Time: 15:59
 */

namespace Home\Controller;
use Think\Controller;

class CommentController extends Controller
{
    public function reply(){
        if (IS_POST){
            $model = D('Admin/CommentReply');
            if ($model->create(I('post.'),1)){
                if ($model->add())
                    $this->success(array(
                        'face' => session('face'),
                        'username' => session('m_username'),
                        'addtime' => date('Y-m-d H:i:s'),
                        'content' => I('post.content'),
                    ));
            }
            $this->error($model->getError());
        }
    }

    public function ajaxGetPl(){
        $goodsId = I('get.goods_id');
        $model = D('Admin/Comment');
        $data = $model->search($goodsId,5);
        echo json_encode($data);
    }

    public function add(){
        if (IS_POST){
            $model = D('Admin/Comment');
            if ($model->create(I('post.'),1)){
                if ($id = $model->add()){
                    $this->success(array(
                       'id' => $id,
                       'face' => session("face"),
                       'username' => session("m_username"),
                       'addtime' => date("Y-m-d H:i:s"),
                       'content' => I('post.content'),
                       'star' => I('post.star'),
                    ),'',TRUE);

                }
                $this->error($model->getError(),'',TRUE);
            }
        }
    }
}